//
//  BKXueFeiZhuSuView.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/1.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKXueFeiZhuSuView.h"
#import "BKBKLiuXueTableViewCell.h"
static NSString *jiangxuejin = @"jxj";

@implementation BKXueFeiZhuSuView

- (void)awakeFromNib{

    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BKBKLiuXueTableViewCell class]) bundle:nil] forCellReuseIdentifier:jiangxuejin];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    BKBKLiuXueTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:jiangxuejin];
    
    if (indexPath.row%2==0) {
        cell.backgroundColor = [UIColor clearColor];
    }else{
        cell.backgroundColor = [UIColor colorWithRed:0.914 green:0.965 blue:0.980 alpha:1.000];
    }
    
    
  
    
    if (indexPath.row ==0 ) {
        cell.zhuanye.text = @"奖学金名称";
        cell.xiangmu.text = @"金额";
        cell.xuexiao.text = @"条件";
        
        
    }else{
        
        cell.zhuanye.text = _dataArray[indexPath.row-1][@"ming"];
        cell.xiangmu.text = _dataArray[indexPath.row-1][@"edu"];
        
       
        cell.xuexiao.text = _dataArray[indexPath.row-1][@"biaozhun"];
        
            }
    return cell;
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [_dataArray count]+1;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        return 44;
    }
    
    NSString *text = _dataArray[indexPath.row-1][@"ming"];
    UIFont *textFont = [UIFont systemFontOfSize:17];
    
    CGSize size = CGSizeMake(tableView.frame.size.width/3-10, 1000);
    
    //获取当前那本属性
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:textFont,NSFontAttributeName, nil];
    //实际尺寸
    CGSize actualSize = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    
    
    NSString *biaozhun = _dataArray[indexPath.row-1][@"biaozhun"];
    
    
    
    
    CGSize actualSize1 = [biaozhun boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
  
    if (actualSize.height>actualSize1.height) {
        if (actualSize.height>44) {
            return actualSize.height;
        }else{
        
            return 44;
            
        }
    }else{
    
        if (actualSize1.height>44) {
            return actualSize1.height;
        }else{
        
            return 44;
        }
    }
    return 44;
    
    
}


- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 1;
}


@end
